//
//  GuidePlayPicture.m
//  BeautifulShoppings
//
//  Created by GivenBmli on 16/9/13.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "GuidePlayPicture.h"
#import "BMLcleView.h"
#import "NetworkHandler.h"
#import "TAMacro.h"
#import "GuideHomeViewController.h"
#define URL @"http://api.liwushuo.com/v2/banners"
@interface GuidePlayPicture ()<BMLcleViewDelegate>
@property(nonatomic, retain)BMLcleView *cysleView;
@property (nonatomic,retain)NSMutableArray * array;
@end
@implementation GuidePlayPicture
- (instancetype)initWithFrame:(CGRect)frame {
    self  = [super initWithFrame:frame];
    if (self) {
        [self creatSubview:frame];
        [self getImagesData];
    }
    return self;
}
- (NSMutableArray *)array{
    if (!_array) {
        self.array = [NSMutableArray array];
    }
    return _array;
}
- (void)creatSubview:(CGRect)frame {
    NSMutableArray *array = [NSMutableArray array];
    //初始化滚动视图对象:
    self.cysleView = [[BMLcleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 3.5) DataSource:array TimeInterval:1.5];
    _cysleView.delegate = self;
    [self addSubview:_cysleView];

}
- (void)getImagesData {
    NSMutableArray *dataSource = [NSMutableArray array];
    [NetworkHandler getDataByURLString:URL BodyString:nil WithDataBlock:^(id result) {
        NSDictionary *dic = [result objectForKey:@"data"];
        NSArray *arr = [dic objectForKey:@"banners"];
        for (NSDictionary *dic2 in arr) {
            NSArray *str2 = [dic2 objectForKey:@"image_url"];
            if (str2 == nil) {
                self.Strid = @"kong";
            }else {
                {
                    NSString *str = [dic2 objectForKey:@"image_url"];
                    self.Strid = [dic2 objectForKey:@"target_id"];
                    [self.array addObject:self.Strid];
                    [dataSource addObject:str];
                }
            }
        }
        [_cysleView reloadDataByArray:dataSource];
    }];

    
}
- (void)didClickedItemAtIndexPath:(NSIndexPath *)indexPath {
    self.Strid = self.array[indexPath.item];
    [self.delegate didClickSelectItemAtIndexPathPlayPicture:indexPath str:self.Strid];
    
    
}
@end
